clear all
set more off
cd "C:\Users\jose.balmori\Universidad Anahuac Dropbox\Jose Balmori\Paper 47 e-crime\Data\Final\"
use base_did.dta, clear

label var retail_recreation "Retail and recreation"
label var grocery_pharma "Grocery and pharmacy"
label var parks "Parks"
label var transit_station "Transit stations"
label var workplace "Workplace"
label var residential "Residential"
label var state "State"

cd "C:\Users\jose.balmori\Universidad Anahuac Dropbox\Jose Balmori\Paper 47 e-crime\Paper\output"

  *********************************** 
 * Table 3: Dif-in-Dif by road user
 *********************************** 
 
gen mdate=ym(yr,mes)
format mdate %tm
xtset state mdate

g lockdown = yr == 2020 & (mes>2 & mes<6)

   global dep2 Fraudet Robberyt Theftt RoboCasat RoboVeht

/*Retail and recreation*/

	 foreach var in $dep2 {
		eststo `var': reghdfe  `var' retail_recreation lockdown i.mes i.yr l.`var' [aw=pob], absorb( i.state) cluster(state)
		estadd local fe "X" : `var'
		    sum  `var'  [aw=pob] if (yr<2020 | (yr==2020 & mes<3))
			local  m0 : di %9.2fc r(mean)  	
			estadd local m0   "`m0'" : `var' 
		display _b[retail_recreation]
		local b=_b[retail_recreation]		
		local pch=(`b'  /`m0')*100
		local per : di %9.1fc `pch'
		estadd local per   "`per'\%" : `var' 
	 }
	  
	global label "\shortstack{Rates Per\\100,000 Inh.:}"
	global mgroups " "\shortstack{Fraud}" "\shortstack{Robbery}" "\shortstack{Theft}" "\shortstack{Burglary}" "\shortstack{MVT}" "  
	global pattern "1 1 1 1 1 1"
	esttab Fraudet Robberyt Theftt RoboCasat RoboVeht using "retail.tex" , replace  se  /*
					*/ noconstant  lines 	f	compress    /*
					*/ mlabels(none)   	 /*   
					*/ label 	booktabs  b(%9.3fc) se(%9.3fc) /*
					*/ alignment(C C)   star(* 0.10 ** 0.05 *** 0.01) /*
					*/ keep( *retail_recreation* )     /*
					*/ nobaselevels   /*
					*/ stats(N r2_a fe  k    ,  /*
					*/ labels("N" "Adjusted R-squared"  /*
					*/ "Baseline FE" "\hline \vspace{-3mm}"   )  /*
					*/	 fmt(%9.0fc %9.3fc %9.3fc  %9.3fc  %9.3fc %9.3fc )  )    /*
					*/ mgroups( $mgroups , lhs("\textsc{${label}}") /*
					*/ pattern( $pattern ) span  /*
					*/ prefix(\multicolumn{@span}{c}{) suffix(})   erepeat(\cmidrule(lr){@span}))

/*residential*/

	 foreach var in $dep2 {
		eststo `var': reghdfe  `var' residential lockdown i.mes i.yr l.`var' [aw=pob], absorb( i.state) cluster(state)
		estadd local fe "X" : `var'
		    sum  `var'  [aw=pob] if (yr<2020 | (yr==2020 & mes<3))
			local  m0 : di %9.2fc r(mean)  	
			estadd local m0   "`m0'" : `var' 
		display _b[residential]
		local b=_b[residential]		
		local pch=(`b'  /`m0')*100
		local per : di %9.1fc `pch'
		estadd local per   "`per'\%" : `var' 
	 }
	  
	global label "\shortstack{Rates Per\\100,000 Inh.:}"
	global mgroups " "\shortstack{Fraud}" "\shortstack{Robbery}" "\shortstack{Theft}" "\shortstack{Burglary}" "\shortstack{MVT}" "  
	global pattern "1 1 1 1 1 1"
	esttab Fraudet Robberyt Theftt RoboCasat RoboVeht using "residential.tex" , replace  se  /*
					*/ noconstant  lines 	f	compress    /*
					*/ mlabels(none)   	 /*   
					*/ label 	booktabs  b(%9.3fc) se(%9.3fc) /*
					*/ alignment(C C)   star(* 0.10 ** 0.05 *** 0.01) /*
					*/ keep( *residential* )     /*
					*/ nobaselevels   /*
					*/ stats(N r2_a fe  k    ,  /*
					*/ labels("N" "Adjusted R-squared"  /*
					*/ "Baseline FE" "\hline \vspace{-3mm}"   )  /*
					*/	 fmt(%9.0fc %9.3fc %9.3fc  %9.3fc  %9.3fc %9.3fc )  )    /*
					*/ mgroups( $mgroups , lhs("\textsc{${label}}") /*
					*/ pattern( $pattern ) span  /*
					*/ prefix(\multicolumn{@span}{c}{) suffix(})   erepeat(\cmidrule(lr){@span}))
					
/*transit_station*/
/*
	 foreach var in $dep2 {
		eststo `var': reghdfe  `var' grocery_pharma lockdown i.mes i.yr l.`var' [aw=pob], absorb( i.state) cluster(state)
		estadd local fe "X" : `var'
		    sum  `var'  [aw=pob] if (yr<2020 | (yr==2020 & mes<3))
			local  m0 : di %9.2fc r(mean)  	
			estadd local m0   "`m0'" : `var' 
		display _b[grocery_pharma]
		local b=_b[grocery_pharma]		
		local pch=(`b'  /`m0')*100
		local per : di %9.1fc `pch'
		estadd local per   "`per'\%" : `var' 
	 }
	  
	global label "\shortstack{Rates Per\\100,000 Inh.:}"
	global mgroups " "\shortstack{Fraud}" "\shortstack{Embezz.}" "\shortstack{Robbery}" "\shortstack{Theft}" "\shortstack{Burglary}" "\shortstack{MVT}" "\shortstack{Extortion}" "\shortstack{Vandalism}" "  
	global pattern "1 1 1 1 1 1 1 1 1"
	esttab Fraudet Robberyt Theftt RoboCasat RoboVeht Extorsiont AbusoConft Propertyt using "grocery_pharma.tex" , replace  se  /*
					*/ noconstant  lines 	f	compress    /*
					*/ mlabels(none)   	 /*   
					*/ label 	booktabs  b(%9.3fc) se(%9.3fc) /*
					*/ alignment(C C)   star(* 0.10 ** 0.05 *** 0.01) /*
					*/ keep( *grocery_pharma* )     /*
					*/ nobaselevels   /*
					*/ stats(N r2_a fe  k    ,  /*
					*/ labels("N" "Adjusted R-squared"  /*
					*/ "Baseline FE" "\hline \vspace{-3mm}"   )  /*
					*/	 fmt(%9.0fc %9.3fc %9.3fc  %9.3fc  %9.3fc %9.3fc )  )    /*
					*/ mgroups( $mgroups , lhs("\textsc{${label}}") /*
					*/ pattern( $pattern ) span  /*
					*/ prefix(\multicolumn{@span}{c}{) suffix(})   erepeat(\cmidrule(lr){@span}))
	*/				
/*workplace*/

	 foreach var in $dep2 {
		eststo `var': reghdfe  `var' workplace lockdown i.mes i.yr l.`var' [aw=pob], absorb( i.state) cluster(state)
		estadd local fe "X" : `var'
		    sum  `var'  [aw=pob] if (yr<2020 | (yr==2020 & mes<3))
			local  m0 : di %9.2fc r(mean)  	
			estadd local m0   "`m0'" : `var' 
		display _b[workplace]
		local b=_b[workplace]		
		local pch=(`b'  /`m0')*100
		local per : di %9.1fc `pch'
		estadd local per   "`per'\%" : `var' 
	 }
	  
	global label "\shortstack{Rates Per\\100,000 Inh.:}"
	global mgroups " "\shortstack{Fraud}" "\shortstack{Robbery}" "\shortstack{Theft}" "\shortstack{Burglary}" "\shortstack{MVT}" "  
	global pattern "1 1 1 1 1 1"
	esttab Fraudet Robberyt Theftt RoboCasat RoboVeht using "workplace.tex" , replace  se  /*
					*/ noconstant  lines 	f	compress    /*
					*/ mlabels(none)   	 /*   
					*/ label 	booktabs  b(%9.3fc) se(%9.3fc) /*
					*/ alignment(C C)   star(* 0.10 ** 0.05 *** 0.01) /*
					*/ keep( *workplace* )     /*
					*/ nobaselevels   /*
					*/ stats(N r2_a fe  k    ,  /*
					*/ labels("N" "Adjusted R-squared" /*
					*/ "Baseline FE" "\hline \vspace{-3mm}"   )  /*
					*/	 fmt(%9.0fc %9.3fc %9.3fc  %9.3fc  %9.3fc %9.3fc )  )    /*
					*/ mgroups( $mgroups , lhs("\textsc{${label}}") /*
					*/ pattern( $pattern ) span  /*
					*/ prefix(\multicolumn{@span}{c}{) suffix(})   erepeat(\cmidrule(lr){@span}))

clear all
